package com.haochang.chunkvod.view.vod.spinner;

import com.haochang.base.BaseTextView;
import com.haochang.base.OnBaseClickListener;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.tools.vod.log.Logger;
import com.haochang.chunkvod.view.vod.popupWindow.IPopWindowLongClickListener;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

/**
 *@author qintao
 *created at 2016/6/1 11:35
 * 点餐查询操作行
 */

public class OperateView extends LinearLayout
{
	private DialogEnum dialogEnum = DialogEnum.SINGLE_REMINDER;
	private ImageView left_img, right_img;
	private BaseTextView left_text, right_text;
	private LinearLayout left_div, right_div;
	private String flow_code;
	private Object obj;
	private Context context;
	private IPopWindowLongClickListener popWindowLongClickListener;

	public OperateView setPopWindowLongClickListener(IPopWindowLongClickListener popWindowLongClickListener)
	{
		this.popWindowLongClickListener = popWindowLongClickListener;
		return this;
	}

	public OperateView(Context context, AttributeSet attrs, int defStyleAttr)
	{
		super(context, attrs, defStyleAttr);
		initView(context);
	}

	public OperateView(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		initView(context);
	}

	public OperateView(Context context)
	{
		super(context);
		initView(context);
	}

	private void initView(Context context)
	{
		this.context = context;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.item_order_query_oper_layout, this, true);
		left_div = (LinearLayout) view.findViewById(R.id.left_div);
		right_div = (LinearLayout) view.findViewById(R.id.right_div);
		left_text = (BaseTextView) view.findViewById(R.id.left_text);
		right_text = (BaseTextView) view.findViewById(R.id.right_text);
		left_img = (ImageView) view.findViewById(R.id.left_img);
		right_img = (ImageView) view.findViewById(R.id.right_img);
		left_div.setOnClickListener(mOnBaseClickListener);
		right_div.setOnClickListener(mOnBaseClickListener);
	}

	public void initViewData(DialogEnum dialogEnum, String flow_code, Object obj)
	{
		this.dialogEnum = dialogEnum;
		this.flow_code = flow_code;
		this.obj = obj;
		if (dialogEnum == DialogEnum.SINGLE_BACK)
		{
			right_text.setText("退单");
			right_img.setImageResource(R.drawable.ic_td);
			setSingleStyle();
		} else if (dialogEnum == DialogEnum.SINGLE_REMINDER)
		{
			right_text.setText("催单");
			right_img.setImageResource(R.drawable.ic_cd);
			setSingleStyle();
		} else if (dialogEnum == DialogEnum.SINGLE_CANCAL)
		{
			right_text.setText("取消赠送");
			right_img.setImageResource(R.drawable.ic_give);
			setSingleStyle();
		} else if (dialogEnum == DialogEnum.SINGLE_CHANGE)
		{
			right_text.setText("更换");
			right_img.setImageResource(R.drawable.ic_change);
			setSingleStyle();
		} else if (dialogEnum == DialogEnum.DOUBLE_REMINDER_BACK)
		{
			left_text.setText("催单");
			left_img.setImageResource(R.drawable.ic_cd);
			right_text.setText("退单");
			right_img.setImageResource(R.drawable.ic_td);
		} else if (dialogEnum == DialogEnum.DOUBLE_REMINDER_CANCAL)
		{
			left_text.setText("催单");
			left_img.setImageResource(R.drawable.ic_cd);
			right_text.setText("取消赠送");
			right_img.setImageResource(R.drawable.ic_give);
		} else if (dialogEnum == DialogEnum.DOUBLE_REMINDER_CHANGE)
		{
			left_text.setText("催单");
			left_img.setImageResource(R.drawable.ic_cd);
			right_text.setText("更换");
			right_img.setImageResource(R.drawable.ic_change);
		}
	}

	/**
	 * 设置右边区域是否显示
	 * @return
	 */
	public void setSingleStyle()
	{
		left_div.setVisibility(View.GONE);
	}

	private OnBaseClickListener mOnBaseClickListener = new OnBaseClickListener()
	{
		@Override
		public void onBaseClick(View v)
		{
			switch (dialogEnum)
			{
			case SINGLE_BACK:
				if (popWindowLongClickListener != null)
				{
					popWindowLongClickListener.back(obj, flow_code);
				}
				break;
			case SINGLE_CANCAL:
				if (popWindowLongClickListener != null)
				{
					popWindowLongClickListener.cancelGive(obj, flow_code);
				}
				break;
			case SINGLE_REMINDER:
				if (popWindowLongClickListener != null)
				{
					popWindowLongClickListener.reminder(obj, flow_code);
				}
				break;
			case SINGLE_CHANGE:
				if (popWindowLongClickListener != null)
				{
					popWindowLongClickListener.change(obj, flow_code);
				}
				break;
			case DOUBLE_REMINDER_BACK:
				if (popWindowLongClickListener != null)
				{
					if (v.getId() == R.id.left_div)
					{
						popWindowLongClickListener.reminder(obj, flow_code);
					} else
					{
						popWindowLongClickListener.back(obj, flow_code);
					}
				}
				break;
			case DOUBLE_REMINDER_CANCAL:
				if (popWindowLongClickListener != null)
				{
					if (v.getId() == R.id.left_div)
					{
						popWindowLongClickListener.reminder(obj, flow_code);
					} else
					{
						popWindowLongClickListener.cancelGive(obj, flow_code);
					}
				}
				break;
			case DOUBLE_REMINDER_CHANGE:
				if (popWindowLongClickListener != null)
				{
					if (v.getId() == R.id.left_div)
					{
						popWindowLongClickListener.reminder(obj, flow_code);
					} else
					{
						popWindowLongClickListener.change(obj, flow_code);
					}
				}
				break;

			default:
				break;
			}
		}
	};

	public enum DialogEnum
	{
		/**
		 * 单按钮-催单
		 */
		SINGLE_REMINDER,
		/**
		 * 单按钮-退单
		 */
		SINGLE_BACK,
		/**
		 * 单按钮-取消赠送
		 */
		SINGLE_CANCAL,
		/**
		 * 单按钮-更换
		 */
		SINGLE_CHANGE,
		/**
		 * 双按钮-催单-取消赠送
		 *
		 */
		DOUBLE_REMINDER_CANCAL,
		/**
		 * 双按钮-催单-退单
		 */
		DOUBLE_REMINDER_BACK,
		/**
		 * 双按钮-催单-更换
		 */
		DOUBLE_REMINDER_CHANGE;
	}
}
